//
//  MCNewActivityDetailViewController.m
//  TLYL
//
//  Created by miaocai on 2017/11/22.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCTNewActivityhdViewController.h"
#import "MCNewActGetMoneyModel.h"
#import "MCNewActCharModel.h"

@interface MCTNewActivityhdViewController ()

@property (nonatomic,weak) UILabel *myLabel;
@property (nonatomic,weak) UIButton *btn;
@property (nonatomic,strong) MCNewActGetMoneyModel *getMoneyModel;
@property (nonatomic,strong) MCNewActCharModel *charModel;
@end

@implementation MCTNewActivityhdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpUI];
    self.navigationItem.title = @"活动详情";
    //    [self loadData];
}
-(void)setUpUI{
    
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.view.backgroundColor = RGB(245, 245, 245);
    UIScrollView *bases = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:bases];
    
    bases.contentSize = CGSizeMake(G_SCREENWIDTH - MC_REALVALUE(26), G_SCREENHEIGHT + 300);
    UIImageView *titleImageV = [[UIImageView alloc] init];
    [bases addSubview:titleImageV];
    titleImageV.image = [UIImage imageNamed:@"huodong03"];
    
    [titleImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bases).offset(13);
        make.width.equalTo(@(G_SCREENWIDTH - MC_REALVALUE(26)));
        make.height.equalTo(@(92));
        make.top.equalTo(bases).offset(13);
        
    }];
    UILabel *titleLabel =  [[UILabel alloc] init];
    [bases addSubview:titleLabel];
    titleLabel.text = @"狗年新春首充送好礼";
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.textColor = RGB(249, 84, 83);
    titleLabel.font = [UIFont boldSystemFontOfSize:MC_REALVALUE(14)];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleImageV.mas_bottom).offset(MC_REALVALUE(13));
        
    }];
    
    UILabel *dateTileLabel =  [[UILabel alloc] init];
    [bases addSubview:dateTileLabel];
    dateTileLabel.textAlignment = NSTextAlignmentLeft;
    dateTileLabel.text = @"活动时间：2018-02-16--2018-02-23";
    dateTileLabel.textColor = RGB(99, 99, 99);
    dateTileLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [dateTileLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(titleLabel.mas_bottom).offset(MC_REALVALUE(13));
        
    }];
    
//    UILabel *titleSubLabel =  [[UILabel alloc] init];
//    [bases addSubview:titleSubLabel];
//    titleSubLabel.textAlignment = NSTextAlignmentLeft;
//    titleSubLabel.text = @"开始时间：2018-02-16--活动结束前24小时通知";
//    titleSubLabel.textColor = RGB(99, 99, 99);
//    titleSubLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
//    [titleSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.right.equalTo(titleImageV);
//        make.top.equalTo(dateTileLabel.mas_bottom).offset(MC_REALVALUE(13));
//
//    }];
    
    
    //    UILabel *lineTitleLabel =  [[UILabel alloc] init];
    //    [bases addSubview:lineTitleLabel];
    //    lineTitleLabel.backgroundColor = RGB(136, 136, 136);
    //    [lineTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.right.equalTo(titleImageV);
    //        make.top.equalTo(titleSubLabel.mas_bottom).offset(MC_REALVALUE(10));
    //        make.height.equalTo(@(0.5));
    //    }];
    //
    
    UILabel *contentLabel =  [[UILabel alloc] init];
    [bases addSubview:contentLabel];
    contentLabel.text = @"活动内容：";
    contentLabel.textAlignment = NSTextAlignmentLeft;
    contentLabel.textColor = RGB(46, 46, 46);
    contentLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(11)];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(dateTileLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    UILabel *contentSubLabel =  [[UILabel alloc] init];
    [bases addSubview:contentSubLabel];
    contentSubLabel.numberOfLines = 0;
    contentSubLabel.text = @"每日首充金额100元以上即可联系客服申请首存金额的10%彩金，满足【首充金额+赠送金额】的8倍流水后方可提款（例：当日首充金额为1000，则可获得活动彩金100元，需满足流水（1000+100）*8后方可提款）";
    contentSubLabel.textAlignment = NSTextAlignmentLeft;
    contentSubLabel.textColor = RGB(99, 99, 99);
    contentSubLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [contentSubLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(contentLabel.mas_left).offset(MC_REALVALUE(10));
        make.right.equalTo(titleImageV.mas_right);
        make.top.equalTo(contentLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    
    //    UIView *bgVIew = [[UIView alloc] init];
    //    [bases addSubview:bgVIew];
    //    [bgVIew mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.right.equalTo(titleImageV);
    //        make.top.equalTo(contentSubLabel.mas_bottom).offset(MC_REALVALUE(10));
    //        make.height.equalTo(@(400));
    //    }];
    //    bgVIew.layer.borderWidth = 0.5;
    //    bgVIew.layer.borderColor = RGB(136, 136, 136).CGColor;
    //
    //    NSArray *cArr = @[@"1彩金",@"5彩金",@"10彩金",@"20彩金",@"50彩金",@"100彩金",@"500彩金",@"1000彩金",@"3000彩金",@"5000彩金"];
    //    for (NSInteger i = 0; i<cArr.count; i++) {
    //        UILabel *chongJinLabel = [[UILabel alloc] init];
    //        [bgVIew addSubview:chongJinLabel];
    //        chongJinLabel.textAlignment = NSTextAlignmentCenter;
    //        chongJinLabel.text = cArr[i];
    //        chongJinLabel.textColor = RGB(99, 99, 99);
    //        chongJinLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    //        chongJinLabel.layer.borderWidth = 0.25;
    //        chongJinLabel.layer.borderColor = RGB(136, 136, 136).CGColor;
    //        chongJinLabel.frame = CGRectMake(0.5*(G_SCREENWIDTH - MC_REALVALUE(26)), 40*i, 0.5*(G_SCREENWIDTH - MC_REALVALUE(26)), 40);
    //    }
    //
    //
    //    NSArray *jArr = @[@"500元",@"2000元",@"5000元",@"10000元",@"30000元",@"100000元",@"300000元",@"500000元",@"1000000元",@"2000000元"];
    //    for (NSInteger i = 0; i<jArr.count; i++) {
    //        UILabel *jiangLabel = [[UILabel alloc] init];
    //        [bgVIew addSubview:jiangLabel];
    //        jiangLabel.textAlignment = NSTextAlignmentCenter;
    //        jiangLabel.text = jArr[i];
    //        jiangLabel.textColor = RGB(99, 99, 99);
    //        jiangLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    //        jiangLabel.layer.borderWidth = 0.25;
    //        jiangLabel.layer.borderColor = RGB(136, 136, 136).CGColor;
    //        jiangLabel.frame = CGRectMake(0, 40*i, 0.5*(G_SCREENWIDTH - MC_REALVALUE(26)), 40);
    //    }
    
    UILabel *guizeLabel =  [[UILabel alloc] init];
    [bases addSubview:guizeLabel];
    guizeLabel.text = @"活动规则：";
    guizeLabel.textAlignment = NSTextAlignmentLeft;
    guizeLabel.textColor = RGB(46, 46, 46);
    guizeLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(11)];
    [guizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(contentSubLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    
    UILabel *infoLabel =  [[UILabel alloc] init];
    [bases addSubview:infoLabel];
    infoLabel.numberOfLines = 0;
    
    infoLabel.textAlignment = NSTextAlignmentLeft;
    infoLabel.textColor = RGB(99, 99, 99);
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"1、腾讯分分彩和台湾5分彩流水不计算在活动流水之内，其余彩种都可参加本活动。\n2、每日仅限前1000名会员参加，活动奖金为当日首充金额的10%（奖金最低10元，最高3000元）\n3、本活动只限用户当日首次充值申请，且在当日23:59前完成所需流水，未达到出款流水要求，次日将重新开始计算流水，否则作废。\n4、会员活动期间内，玩法投注不得超过该玩法投注总码的70%，即定位胆必须小于等于7注，二码必须小于等于70注，三码必须小于等于700注，四星必须小于等于7000注，五星必须小于等于70000注。如发现违规投注情况，均视作放弃本次活动。\n5、正信在线禁止一切违规对打套利行为，对此平台将实时监控，同一个ip，平台帐号，绑定的姓名以及卡号，每日只可参与一次；如有发现违规套利账户，将永久冻结。\n6、正信在线保留对此活动修改的权限。"];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:5];//调整行间距
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attributedString length])];
    infoLabel.attributedText = attributedString;
    infoLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    [infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(titleImageV);
        make.top.equalTo(guizeLabel.mas_bottom).offset(MC_REALVALUE(10));
        
    }];
    
    //    UILabel *myLabel =  [[UILabel alloc] init];
    //    [bases addSubview:myLabel];
    //    myLabel.numberOfLines = 0;
    //    NSString *str = @"今日首充金额：0元 ，累计消费金额：0元，可领取：0元";
    //    NSArray *number = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
    //    myLabel.textColor = RGB(99, 99, 99);
    //    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:str];
    //    for (int i = 0; i < str.length; i ++) {
    //        NSString *a = [str substringWithRange:NSMakeRange(i, 1)];
    //        if ([number containsObject:a]) {
    //          [attributeString addAttributes:@{NSForegroundColorAttributeName:RGB(249, 84, 83),NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} range:NSMakeRange(i, 1)];
    //        }
    //    }
    //    self.myLabel = myLabel;
    //    myLabel.attributedText = attributeString;
    //    myLabel.textAlignment = NSTextAlignmentLeft;
    //    myLabel.textAlignment = NSTextAlignmentCenter;
    //    myLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
    //    [myLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.left.right.equalTo(titleImageV);
    //        make.top.equalTo(infoLabel.mas_bottom).offset(MC_REALVALUE(10));
    //
    //    }];
    
    
    //    UIButton *btn = [[UIButton alloc] init];
    //    [bases addSubview:btn];
    //    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.centerX.equalTo(bases);
    //        make.top.equalTo(myLabel.mas_bottom).offset(MC_REALVALUE(10));
    //        make.height.equalTo(@(40));
    //        make.width.equalTo(@(80));
    //    }];
    //    btn.backgroundColor = [UIColor orangeColor];
    //    [btn setTitle:@"立即领取" forState:UIControlStateNormal];
    //    [btn addTarget:self action:@selector(btnCLick) forControlEvents:UIControlEventTouchUpInside];
    //    self.btn = btn;
    
}
- (void)loadData{
    
    MCNewActGetMoneyModel *getMoneyModel = [[MCNewActGetMoneyModel alloc] init];
    self.getMoneyModel = getMoneyModel;
    [getMoneyModel refreashDataAndShow];
    __weak typeof(self) weakself= self;
    [BKIndicationView showInView:self.view];
    getMoneyModel.callBackSuccessBlock = ^(id manager) {
        NSString *str = @"";
        if ([[NSString stringWithFormat:@"%@",manager[@"RangeMoney"]] isEqualToString:@""] || [manager[@"ReturnMoney"] intValue] == -2) {
            weakself.btn.backgroundColor = RGB(181, 181, 181);
            weakself.btn.enabled = NO;
            str =[NSString stringWithFormat:@"今日首充金额：%d元，累计消费金额：%@元，可领取：0元",[manager[@"ReceiveMoney"] intValue],manager[@"ConsumptionMoney"]];
        }else{
            weakself.btn.backgroundColor = [UIColor orangeColor];
            weakself.btn.enabled = YES;
            str =[NSString stringWithFormat:@"今日首充金额：%d元，累计消费金额：%@元，可领取：%@元",[manager[@"ReceiveMoney"] intValue],manager[@"ConsumptionMoney"],manager[@"RangeMoney"]];
        }
        NSArray *number = @[@"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:str];
        for (int i = 0; i < str.length; i ++) {
            NSString *a = [str substringWithRange:NSMakeRange(i, 1)];
            if ([number containsObject:a]) {
                [attributeString addAttributes:@{NSForegroundColorAttributeName:RGB(249, 84, 83),NSFontAttributeName:[UIFont systemFontOfSize:MC_REALVALUE(12)]} range:NSMakeRange(i, 1)];
            }
        }
        weakself.myLabel.attributedText = attributeString;
        
    };
}
- (void)btnCLick{
    MCNewActCharModel *charModel = [[MCNewActCharModel alloc] init];
    self.charModel = charModel;
    [charModel refreashDataAndShow];
    __weak typeof(self) weakself= self;
    [BKIndicationView showInView:self.view];
    charModel.callBackSuccessBlock = ^(id manager) {
        if ([manager[@"ReturnMoney"] intValue] == 1) {
            [SVProgressHUD showInfoWithStatus:manager[@"Remarks"]];
            [weakself loadData];
        }
    };
}
@end

